package org.aphelie.chronicle.ui.i18n;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;

public class ArcLogger {

	private Plugin plugin;
	
	public ArcLogger(Plugin plugin) {
		this.plugin = plugin;
	}

    /**
     * Returns the symbolic name of the plugin.
     */
    private String getSymbolicName() {
        return plugin.getBundle().getSymbolicName();
    }

    /**
     * Logs the given throwable exception.
     */
    public void log(Throwable throwable) {
        log(new Status(IStatus.ERROR, getSymbolicName(), IStatus.ERROR, throwable.getMessage() != null
                ? throwable.getMessage() : "", throwable));
    }

    /**
     * Logs a message from the specified <code>status</code>.
     */
    public void log(IStatus status) {
        plugin.getLog().log(status);
    }

    /**
     * Logs an error message.
     */
    public void logErrorMessage(String message) {
        log(new Status(IStatus.ERROR, getSymbolicName(), IStatus.ERROR, message, null));
    }

    /**
     * Logs an info message.
     *
     * @param message
     */
    public void logInfoMessage(String message) {
        log(new Status(IStatus.INFO, getSymbolicName(), IStatus.INFO, message, null));
    }

    /**
     * Logs an error message with an embedded status.
     */
    public void logErrorStatus(IStatus status, String message) {
        if (status == null) {
            logErrorMessage(message);
            return;
        }
        MultiStatus multi = new MultiStatus(getSymbolicName(), IStatus.ERROR, message, null);
        multi.add(status);
        log(multi);
    }

    /**
     * Logs a throwable exception.
     */
    public void log(String message, Throwable throwable) {
        log(new Status(IStatus.ERROR, getSymbolicName(), IStatus.ERROR, message, throwable));
    }
	
}
